<script setup lang="ts">
import { $t } from '@/locales';
import { useNaiveForm } from '@/hooks/common/form';

defineOptions({
  name: 'LogSearch'
});

interface Emits {
  (e: 'reset'): void;
  (e: 'search'): void;
}

const emit = defineEmits<Emits>();

const { formRef, validate, restoreValidation } = useNaiveForm();

const model = defineModel<Api.SystemManage.LogSearchParams>('model', { required: true });

async function reset() {
  await restoreValidation();
  emit('reset');
}

async function search() {
  await validate();
  emit('search');
}
</script>

<template>
  <NCard :title="$t('common.search')" :bordered="false" size="small" class="card-wrapper">
    <NForm ref="formRef" :model="model" label-placement="left" :label-width="80">
      <NGrid responsive="screen" item-responsive>
        <NFormItemGi span="24 s:18 m:6" :label="$t('page.manage.log.userId')" path="userId" class="pr-24px">
          <NInput v-model:value="model.userId" :placeholder="$t('page.manage.log.form.userId')" />
        </NFormItemGi>

        <NFormItemGi span="24 s:12 m:6" :label="$t('page.manage.log.methodName')" path="methodName" class="pr-24px">
          <NInput v-model:value="model.methodName" :placeholder="$t('page.manage.log.form.methodName')" />
        </NFormItemGi>

        <NFormItemGi span="24 s:12 m:6" :label="$t('page.manage.log.ip')" path="ip" class="pr-24px">
          <NInput v-model:value="model.ip" :placeholder="$t('page.manage.log.form.ip')" />
        </NFormItemGi>

        <NFormItemGi
          span="24 s:12 m:6"
          :label="$t('page.manage.log.requestMethod')"
          path="requestMethod"
          class="pr-24px"
        >
          <NInput v-model:value="model.requestMethod" :placeholder="$t('page.manage.log.form.requestMethod')" />
        </NFormItemGi>

        <NFormItemGi span="24 s:12 m:12" :label="$t('page.manage.log.requestTime')" path="requestTime" class="pr-24px">
          <NDatePicker v-model:value="model.requestTimeRange" type="datetimerange" clearable />
        </NFormItemGi>

        <!--
        <NFormItemGi span="24 s:12 m:6" :label="$t('page.manage.log.status')" path="status" class="pr-24px">
          <NSelect
            v-model:value="model.status"
            :placeholder="$t('page.manage.user.form.status')"
            :options="translateOptions(enableStatusOptions)"
            clearable
          />
        </NFormItemGi>
-->

        <NFormItemGi span="24 m:12" class="pr-24px">
          <NSpace class="w-full" justify="end">
            <NButton @click="reset">
              <template #icon>
                <icon-ic-round-refresh class="text-icon" />
              </template>
              {{ $t('common.reset') }}
            </NButton>
            <NButton type="primary" ghost @click="search">
              <template #icon>
                <icon-ic-round-search class="text-icon" />
              </template>
              {{ $t('common.search') }}
            </NButton>
          </NSpace>
        </NFormItemGi>
      </NGrid>
    </NForm>
  </NCard>
</template>

<style scoped></style>
